package com.xuecheng.basic.controller;

import com.xuecheng.basic.domain.Category;
import com.xuecheng.commons.model.vo.CategoryVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xuecheng.basic.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程分类前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class CategoryController {

    @Autowired
    private CategoryService  categoryService;

    //  课程分类
    @GetMapping("/category/tree-nodes")
    public ResponseResult Categorylist(){
        //调用方法查询
       return  categoryService.kechengfenlei();

    }
     // 根据id查询分类
    @GetMapping("/category/{id}")
    public ResponseResult findById(@PathVariable("id") String id){ //接受参数
        // 调用方法 返回结果
        Category byId = categoryService.getById(id);
        // 封装VO
        CategoryVo categoryVo = BeanHelper.copyProperties(byId, CategoryVo.class);
        //返回结果
        return ResponseResult.okResult(categoryVo);

    }


}
